mui.init();
mui.plusReady(function() {
	//	window.addEventListener('refreshdom', function(event) {
	//		console.log(event.detail.val);
	//		userindex.reqcode(event.detail.val);
	//	})
	var userindex = new Vue({
		el: "#app",
		data: {
			data: {},
			goods: {},
			postData: {
				trade_pwd: '',
				goods_id: '',
				num: '',
				remark: '',
				username: '',
				address: '',
				mobile: ''
			}

		},
		mounted: function() {
			var _this = this;
			var shareInfo = plus.webview.currentWebview();
			_this.postData.goods_id = shareInfo.nid;
			_this.postData.num = shareInfo.count;
			_this.$nextTick(function() {
				_this.cartView();
			});

		},
		methods: {
			cartView: function() {
				var _this = this;
				app.postUrl(apiurl + 'Mall/preorder.html', {
					goods_id: _this.postData.goods_id
				}, function(res) {
					if(res.status === 1) {
						_this.goods = res.data.goods;
						_this.postData.username = res.data.addr.username;
						_this.postData.address = res.data.addr.addrdesc + ' ' + res.data.addr.address;
						_this.postData.mobile = res.data.addr.mobile;
						
					}
				});

			},
			refresh: function(done) {
				done();
			},
			infinite: function(done) {
				done();
			},
			openwin: function(urls, uid) {
				mui.openWindow({
					url: urls,
					id: uid,
					extras: {
						name: 'mui' //扩展参数
					}
				});
			},
			buyord: function(){
				var _this = this;
				//console.log(JSON.stringify(_this.postData))
				if(_this.postData.username == ''){
					mui.toast('收货人不能为空');
					return;
				}
				if(_this.postData.trade_pwd == ''){
					mui.toast('交易密码不能为空');
					return;
				}
				if(_this.postData.address == ''){
					mui.toast('收货地址不能为空');
					return;
				}
				if(_this.postData.mobile == ''){
					mui.toast('联系方式不能为空');
					return;
				}
				
				app.postUrl(apiurl + 'Mall/buyOrder.html', _this.postData, function(res) {
					console.log(JSON.stringify(res));
					if(res.status === 1){
						app.delcar(_this.postData.goods_id);
						mui.back();
					}
					mui.alert(res.msg);
				});
			}

		}

	});

});